<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class News extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
        
        //Load model
        $this->load->model('blog_m');
    }

    /**
     * Default function
     * @param int $page
     */
    public function index($page = 1)
    {
        //Set params
        $newsId = $this->config->item('NEWS_ID');
        $limit = 10;
        $offset = ($page - 1) * $limit;
        
        //Get data
        $arrNews = $this->blog_m->get_top_object_by_cateId($newsId, $limit, $offset);
        
        //Check total
        if($arrNews['total'] > $limit)
        {
            //Init paging
            $this->load->library('pagination');

            $config['base_url'] = base_url() . '/tin-tuc/trang';
            $config['total_rows'] = $arrNews['total'];
            $config['per_page'] = $limit;
            $config['first_url'] = base_url() . '/tin-tuc';
            $config['anchor_class'] = 'class="link5"';
            $config['cur_tag_open'] = '&nbsp;<strong class="link5">';
            $config['use_page_numbers'] = TRUE;

            $this->pagination->initialize($config);
        }
        
        //Assign to view
        $this->assign('arrNews', $arrNews);
    }
    
    /**
     * View function
     * @param int $id 
     */
    public function view($id = NULL)
    {
        //Set array data default
        $arrData = array();
        
        //Check id valid
        if($id)
        {
            $arrData = $this->blog_m->get_object_detail($id); 
        }
        
        //Assign to view
        $this->assign('arrData', $arrData);
    }

}